package com.sharker.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.sharker.R;
import com.sharker.adapter.CourseAdapter;
import com.sharker.models.data.TryData;
import com.sharker.network.SharkerParams;

import org.xutils.common.Callback;
import org.xutils.x;


/**
 * 项目名称：Sharker-master
 * 类描述：  课程页面
 * 创建人：${丁江楠}
 * 创建时间：2017/4/7 19:30
 * 修改人：${丁江楠}
 * 修改时间：2017/4/7 19:30
 * 修改备注：
 */
public class CourseFragment extends Fragment{

    private RecyclerView mRecycle;
    private CourseAdapter courseAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_course, null);
        mRecycle = (RecyclerView) view.findViewById(R.id.course_recycle);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setAdapter();
    }
    /**
     * 适配的方法
     */
    private void setAdapter() {
        courseAdapter = new CourseAdapter(getActivity());
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
        mRecycle.setLayoutManager(layoutManager);
        mRecycle.addItemDecoration(new DividerItemDecoration(getActivity(),
                DividerItemDecoration.VERTICAL));
        mRecycle.setAdapter(courseAdapter);
        courseAdapter.setmOnCourseClickListener(new CourseAdapter.OnCourseClickListener() {
            @Override
            public void onCourseDesClick(int position) {
                Toast.makeText(getActivity(), "详情", Toast.LENGTH_SHORT).show();
            }
            @Override
            public void onCourseTestClick(int position) {
                Toast.makeText(getActivity(), "测试", Toast.LENGTH_SHORT).show();
            }
        });
    }

    /**
     * 网络请求
     */
    private void getListCourse() {
        SharkerParams params = new SharkerParams("list_try");
        //登录之后拿到的参数
        params.addBodyParameter("session", "001");
        params.addBodyParameter("page_size", "20");
        params.addBodyParameter("page_index", "0");
        x.http().post(params, new Callback.CommonCallback<TryData>() {
            @Override
            public void onSuccess(final TryData result) {
                //拿到内容适配
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

 /*   *//**
     * 详情
     * @param position
     *//*
    @Override
    public void onCourseDesClick(int position) {
        Toast.makeText(getActivity(), "详情", Toast.LENGTH_SHORT).show();
    }
    *//**
     * 测试
     * @param position
     *//*
    @Override
    public void onCourseTestClick(int position) {
          //传递object_id
        Toast.makeText(getActivity(), "测试", Toast.LENGTH_SHORT).show();
    }*/
}
